//
//  XMTitleAndSubTitleView.m
//  XMPayAndRedeemSDK
//
//  Created by Tammy on 16/5/23.
//  Copyright © 2016年 Tammy. All rights reserved.
//

#import "XMTitleAndSubTitleView.h"
#import "UIColor+RGB.h"
#import "XMScreenAdaptation.h"


@interface XMTitleAndSubTitleView ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *valueLabel;
@property (nonatomic, strong) UILabel *descLabel;
@property (nonatomic, strong) UIView * upLine;
@property (nonatomic,strong) UIView * downLine;

@end

@implementation XMTitleAndSubTitleView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    
    self.backgroundColor =  [UIColor whiteColor]; // [UIColor colorWithRed:176/255.0 green:205/255.0 blue:234/255.0 alpha:1];//
    CGFloat originX = 15 * [XMScreenAdaptation adapterMultipleByWidth];
    CGFloat titleLabelWidth = 80.f  * [XMScreenAdaptation adapterMultipleByWidth];
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(originX, 0, titleLabelWidth, CGRectGetHeight(self.frame))];
//    self.titleLabel.backgroundColor = [UIColor whiteColor];// [UIColor colorWithRed:176/255.0 green:205/255.0 blue:234/255.0 alpha:1];
    self.titleLabel.textAlignment = NSTextAlignmentLeft;
    self.titleLabel.font = [UIFont systemFontOfSize:14 * [XMScreenAdaptation adapterMultipleByWidth]];
    self.titleLabel.textColor = [UIColor colorWithRGB:0x333333]; //[XMSDKManager commonFontColor];
    [self addSubview:self.titleLabel];
    
    originX = originX + titleLabelWidth;
    self.valueLabel = [[UILabel alloc] initWithFrame:CGRectMake( originX, 0, CGRectGetWidth(self.frame) - originX - 60, CGRectGetHeight(self.frame))];
//    self.valueLabel.backgroundColor = [UIColor whiteColor];// [UIColor colorWithRed:176/255.0 green:205/255.0 blue:234/255.0 alpha:1];//
    self.valueLabel.textAlignment = NSTextAlignmentLeft;
    self.valueLabel.font = [UIFont systemFontOfSize:14 * [XMScreenAdaptation adapterMultipleByWidth]];
    self.valueLabel.textColor = [UIColor colorWithRGB:0x333333];//[XMSDKManager commonFontColor];
    [self addSubview:self.valueLabel];
    
    self.upLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 0.5)];
    self.upLine.backgroundColor = [UIColor colorWithRGB:0xe0e0e0];
    [self addSubview:self.upLine];
    
    self.downLine = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height, self.frame.size.width, 0.5)];
    self.downLine.backgroundColor = [UIColor colorWithRGB:0xe0e0e0];
    [self addSubview:self.downLine];
    //    self.layer.borderColor = [UIColor colorWithWhite:0.8 alpha:0.9].CGColor;
    //    self.layer.borderWidth = 0.5;
    
}



- (void)setupDatasWithTitle:(NSString *)title value:(NSString *)value {
    self.titleLabel.text = title;
    self.valueLabel.text = value;
}

- (UILabel *)getValueLabel {
    return self.valueLabel;
}

- (UILabel *)getTitleLabel {
    return self.titleLabel;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGRect valueFrame = self.valueLabel.frame;
    valueFrame.size.width = self.frame.size.width - self.titleLabel.frame.origin.x - self.titleLabel.frame.size.width - 20 * [XMScreenAdaptation adapterMultipleByWidth];
    self.valueLabel.frame = valueFrame;
}

- (void)setLineFrom:(int)posiontion{
    
    CGFloat oX = 15 * [XMScreenAdaptation adapterMultipleByWidth];
    // first 0 - 15
    if (posiontion == 1) {
        
        self.downLine.frame = CGRectMake(oX, self.frame.size.height, self.frame.size.width - oX, 0.5);
        // last 15 - 0
    }else if (posiontion == 2){
        self.upLine.frame = CGRectMake(oX, 0, self.frame.size.width - oX, 0.5);
        
        // middle 15 - 15
    }else if(posiontion == 3){
        self.downLine.frame = CGRectMake(oX, self.frame.size.height, self.frame.size.width - oX, 0.5);
        self.upLine.frame = CGRectMake(oX, 0, self.frame.size.width - oX, 0.5);
    }else{
        // 0 - 0
    }
    
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
